<template>
  <q-input
    v-model="field.value"
    filled
    mask="######"
    :label="field.label"
    lazy-rules
    :rules="field.rules ? field.rules : null"
    @click="popProxy"
    bottom-slots
    ref="input"
  >
    <template v-slot:append>
      <q-icon
        name="event"
        class="cursor-pointer"
      >
        <q-popup-proxy
          ref="qMonthProxy"
          transition-show="scale"
          transition-hide="scale"
        >
          <monthpicker color="primary" v-model="field.value" />
        </q-popup-proxy>
      </q-icon>
    </template>

    <template v-slot:hint v-if="field.hint || field.compare">
      <div class="text-bold text-white bg-yellow-10" style="padding: 1px;" v-if="canShowCompare">
        {{field.compare.label ? field.compare.label + '：' : ''}}{{field.compare.value}}
      </div>
      <div v-if="field.hint">{{field.hint}}</div>
    </template>
  </q-input>
</template>
<script>
import { defineComponent } from 'vue';
import monthpicker from 'src/components/MonthPicker.vue';

export default defineComponent({
  name: 'monthinput',
  components: {
    monthpicker
  },
  props: {
    field: {
      type: Object,
      default: () => {}
    }
  },
  emits: ['update:modelValue'],
  data () {
    const self = this;
    return {

    }
  },
  methods: {
    popProxy () {
      this.$refs.qMonthProxy.show();
    }
  },
  watch: {
    'field.value' (val) {
      this.$refs.qMonthProxy.hide();
      this.$emit('update:modelValue', val);
    }
  },
  computed: {
    canShowCompare () {
      /*
        compare的值
        compare: {
          label, // 标题
          value, // 对比的值
          always // true-有数据就显示 false-值不同，再显示
        } */
      return this.field.compare && (this.field.compare.always || this.field.compare.value != this.field.value);
    }
  }
});
</script>
